
import gevent, time
from gevent import monkey
from urllib import request

monkey.patch_all() #把当前程序所有io操作都坐上标记使他们自动切换

def f(url):
    print('GET: %s', url)
    resp = request.urlopen(url)
    data = resp.read()
    print('%d bytes received from %s' % (len(data), url))

start_time = time.time()
gevent.joinall([
    gevent.spawn(f, 'https://www.python.org'),
    gevent.spawn(f, 'https://www.yahoo.com'),
    gevent.spawn(f, 'https://www.baidu.com')
])
print('time:', time.time() - start_time)

